home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1994
/
MacHack 1994.toast
/
MacHack™ 1987-1994
/
MacHack™ '93
/
Hacks '93
/
CountPatches
/
NumToPStr.c
< prev
next >
Wrap
Text File
|
1993-06-17
|
1KB
|
57 lines
#define convLength 5
StringPtr NumToPStr(short n);
StringPtr StrPCat(StringPtr a, StringPtr b);
/*
* don't reference globals in any of these routines. Globals in an INIT depend
* upon the SetUpA4()/RememberA4() conventions. See Think C's manual for more
* details.
*/
/*******************************************************************************
NumToPStr
Convert a short into a decimal string, preceded by blanks. If you want
the number preceeded by zeros, eliminate the line
if (n == 0) conv[0] = ' ';
from the for loop.
*******************************************************************************/
StringPtr NumToPStr(short n)
{
static unsigned char result[] = "$$$$$";
char conv[] = "0123456789";
short i;
for (i = 0; i < convLength; ++i) {
result[(convLength-1)-i] = conv[(n % 10)];
n /= 10;
if (n == 0) conv[0] = ' ';
}
result[0] = convLength-1;
return result;
}
/*******************************************************************************
StrPCat
Concatenate two pascal strings, returning a Pascal string.
*******************************************************************************/
StringPtr StrPCat(StringPtr a, StringPtr b)
{
static Str255 result;
short strSize;
strSize = *a+*b+1;
BlockMove(a, result, *a+1);
BlockMove(b+1, result+*a+1, *b);
*result = strSize-1;
return result;
}